﻿/*
   @Description:房源详情页签约tab页js
   @Author:ZB,YPL
   @Date:2014-07-25 
 */
var GetOnlyTrust = {};
var propertyonlytrustobtain = GetOnlyTrust;
GetOnlyTrust.init = function () {
    $(function () {
        //新增签约
        $("#btnAddOnlyTrust2").bind("click", function () {
            var currentProperty = $("#PropertyKeyIdhid").val();
            $.dialog({
                id: "dialogAddExclusive",
                lock: true,
                title: "新增签约",
                content: $("#popAddExclusive").html() + '<input type="hidden" id="currentPropertyId" value="' + currentProperty + '" />'
            });
            //设置文本域输入后剩余的字数
            $.inputStatistics2("div.aui_content #txtComment");

            PopupWindow.makeUploadBtn();
            //签约订金验证，只能为数字
            agencyVerify.nonnegativeIntInput("#txtCashTrust", true);
            //返佣金额验证
            agencyVerify.nonnegativeInput("input[deposit=deposit]");
            EmployeePrompt.getDepartAndEmployeeByInput(null, "hidDepartmentKeyId", "btnRegisterPerson", "hidUserId", false, "private", 1, "请选择业务员", null, null, true);
        });

        //删除签约
        $('.btnDelOnly').click(function () {
            var keyId = $(this).attr('keyId');
            if (!ListAndDetailRight.CheckRightRol(this, "Property.OnlyTrust.Delete", true)) {
                return false;
            }
            art.dialog({
                content: '<div class="tc">您是否删除？</div>',
                lock: true,
                ok: function () {
                    var reqData = { 'keyId': keyId };
                    $.AjaxAgency('/property/property-only-trust-remove-ajax', reqData, function (data) {
                        if (data == 'ok') {
                            GetOnlyTrust.refresh();
                        } else {
                            $.OKDialogAgency('<div class="tc">'+data+'</div>');
                        }
                    });
                    return true;
                },
                cancelVal: '关闭',
                cancel: true
            });

        });

        //编辑签约
        $('.btnEditOnly').click(function () {
            var keyId = $(this).attr('keyId');
            var reqData = { 'keyId': keyId };
            if (!ListAndDetailRight.CheckRightRol(this, "Property.OnlyTrust.Modify", true)) {
                return false;
            }
            $.AjaxAgency('/property/property-only-trust-find', reqData, function (data) {
                if (data.indexOf("#noYes") == 0) {
                    $.OKDialogAgency('<div class="tc">' + data + '</div>');
                } else {
                    art.dialog({
                        id: 'EditOnly',
                        title: '编辑签约',
                        content: data,
                        lock: true,
                    });
                    //设置文本域输入后剩余的字数
                    $.inputStatistics2("div.aui_content #txtComment");
                    //返佣金额验证
                    agencyVerify.nonnegativeInput("input[deposit=deposit]");

                    EmployeePrompt.getDepartAndEmployeeByInput(null, "hidDepartmentKeyId", "btnRegisterPerson", "hidUserId", false, "private", 1, "请选择业务员", null, null, true);
                    PopupWindow.makeUploadBtn();
                }
            });

        });

        //查看签约
        $('.btnSeeOnly').click(function () {
            var keyId = $(this).attr('keyId');
            var reqData = {
                'keyId': keyId,
                "type": "see"
            };
            $.AjaxAgency('/property/property-only-trust-find', reqData, function (data) {
                if (data.indexOf("#noYes") == 0) {
                    $.OKDialogAgency('<div class="tc">' + data + '</div>');
                } else {
                    art.dialog({
                        id: 'EditOnly',
                        title: '查看签约',
                        content: data,
                        lock: true,
                    });
                }
            });

        });
    });

}



GetOnlyTrust.onlyTrustEdit = function () {
    alert('btnOnlyTrustEdit2');
};

//刷新页面方法
GetOnlyTrust.refresh = function () {
    var urlParamters = $('#parPropertyKeyId').val();
    if ($("#btnAddOnlyTrust2").length > 0) {
        urlParamters += "&HaveAddOnlyTrustRight=True";
    }
    urlParamters += "&random=" + Math.random();
    $.get("/property/property-only-trust-obtain?" + urlParamters, function (data2) {
        $('#contentdiv').html(data2);
        GetOnlyTrust.init();
    });
};
